﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using CNotebook.Inventory;

namespace NotebookS2.Reports.Crystal.Inventory
{
    public partial class CRYSTAL_STOCKMOVEMENT_PARAM : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public CRYSTAL_STOCKMOVEMENT_PARAM()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        void BindPhysicalCount()
        {
            PhysicalCountManager oManager = new PhysicalCountManager();
            DataTable dt = new DataTable();

            try
            {
                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();
                dt = oManager.GetDocuments(cboWarehouse.EditValue.ToString());
                oManager.Close();

                cboPhysicalCount.Properties.Columns.Clear();
                cboPhysicalCount.Properties.DataSource = dt;
                cboPhysicalCount.Properties.DisplayMember = "DocNum";
                cboPhysicalCount.Properties.ValueMember = "DocNum";
                DevExpress.XtraEditors.Controls.LookUpColumnInfo col;

                col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("DocNum", "DocNum", 100);

                col.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;

                cboPhysicalCount.Properties.Columns.Add(col);
                cboPhysicalCount.Properties.ShowHeader = false;

                cboPhysicalCount.Refresh();
            }
            catch
            {
            }

        }

        void BindWarehouse()
        {
            try
            {
                WarehouseManager oManager = new WarehouseManager();
                DataTable dt = new DataTable();
                oManager.ConnectionString = this.ConnectionString;

                oManager.Open();

                dt = oManager.GetWarehouse();

                oManager.Close();


                cboWarehouse.Properties.DataSource = dt;
                cboWarehouse.Properties.DisplayMember = "Dscription";
                cboWarehouse.Properties.ValueMember = "Code";
                DevExpress.XtraEditors.Controls.LookUpColumnInfo col;

                col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Dscription", "Dscription", 100);

                col.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;

                cboWarehouse.Properties.Columns.Add(col);
                cboWarehouse.Properties.ShowHeader = false;

                cboWarehouse.Refresh();

            }
            catch
            {
            }
        }

        private void CRYSTAL_STOCKMOVEMENT_PARAM_Load(object sender, EventArgs e)
        {
            dtAsOfDate.EditValue = System.DateTime.Now;

            BindWarehouse();
            BindPhysicalCount();
        }

        private void btnPrintPreview_Click(object sender, EventArgs e)
        {
            try
            {
                CRYSTAL_STOCKMOVEMENT oForm = new CRYSTAL_STOCKMOVEMENT();

                oForm.ConnectionString = this.ConnectionString;
                oForm.CountDocumentNo = cboPhysicalCount.EditValue.ToString();
                oForm.WarehouseCode = cboWarehouse.EditValue.ToString();
                oForm.ItemCode = txtItemCode.Text;
                oForm.AsOfDate = (DateTime)dtAsOfDate.EditValue;
                oForm.LotNumber = this.txtLotNumber.Text;
                oForm.ShowDialog();
            }
            catch
            {
                MessageBox.Show("Please complete the parameters!!!", "Parameters", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cboWarehouse_EditValueChanged(object sender, EventArgs e)
        {
            BindPhysicalCount();
        }

        private void txtItemCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            FND_ITEM oFindItemForm = new FND_ITEM();
            oFindItemForm.ConnectionString = this.ConnectionString;
            oFindItemForm.ShowDialog();

            if (oFindItemForm.SelectedItemCode != null)
            {
                txtItemCode.Text = oFindItemForm.SelectedItemCode;
                txtItemName.Text = oFindItemForm.SelectedItemDescription;
            }
        }
    }
}
